package cn.harry.wx.entity;

import cn.harry.wx.form.WxQrCodeForm;
import cn.hutool.core.date.DatePattern;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

/**
 * 公众号带参二维码
 *
 * @author honghh
 * Date 2021-04-08 16:19:27
 * Copyright (C) www.tech-harry.cn
 */
@Data
@TableName("wx_qr_code")
public class WxQrCode implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * ID
     */
    @TableId
    @ApiModelProperty(value = "ID")
    private Long id;

    /**
     * appid
     */
    @ApiModelProperty(value = "appid")
    private String appid;
    /**
     * 是否为临时二维码
     */
    @ApiModelProperty(value = "是否为临时二维码")
    @TableField(whereStrategy = FieldStrategy.NEVER)
    private boolean isTemp;
    /**
     * 场景值ID
     */
    @ApiModelProperty(value = "场景值ID")
    private String sceneStr;
    /**
     * 二维码ticket
     */
    @ApiModelProperty(value = "二维码ticket")
    private String ticket;
    /**
     * 二维码图片解析后的地址
     */
    @ApiModelProperty(value = "二维码图片解析后的地址")
    private String url;
    /**
     * 该二维码失效时间
     */
    @JsonFormat(pattern = DatePattern.NORM_DATETIME_PATTERN, timezone = "GMT+8")
    @ApiModelProperty(value = "该二维码失效时间")
    private Date expireTime;
    /**
     * 创建时间
     */
    @JsonFormat(pattern = DatePattern.NORM_DATETIME_PATTERN, timezone = "GMT+8")
    @ApiModelProperty(value = "创建时间")
    private Date createTime;
    /**
     * 修改时间
     */
    @JsonFormat(pattern = DatePattern.NORM_DATETIME_PATTERN, timezone = "GMT+8")
    @ApiModelProperty(value = "修改时间")
    private Date modifyTime;
    /**
     * 有效状态：0->无效；1->有效
     */
    @TableLogic
    @ApiModelProperty(value = "有效状态：0->无效；1->有效")
    private Integer valid;
    /**
     * 开始时间
     */
    @JsonIgnore
    @TableField(exist = false)
    private String beginTime;

    /**
     * 结束时间
     */
    @JsonIgnore
    @TableField(exist = false)
    private String endTime;
    public WxQrCode() {
    }

    public WxQrCode(WxQrCodeForm form, String appid) {
        this.appid = appid;
        this.isTemp = form.getIsTemp();
        this.sceneStr = form.getSceneStr();
        this.createTime = new Date();
    }
}
